//
//  MAPYNavView.swift
//  Mars Proxy
//
//  Created by PowerfullClean on 2023/10/16.
//

import UIKit

class MAPYNavView: UIView {
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: mapy_SCREEN_WIDTH, height: MAPYCommon.mapy_navHegiht))
        mapy_initViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func mapy_initViews()  {
        addSubview(mapy_leftButton)
        addSubview(mapy_titleLabel)
        
        mapy_leftButton.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-26)
            make.left.equalToSuperview().offset(20)
            make.size.equalTo(24)
        }
        mapy_titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(mapy_leftButton.snp.centerY)
            make.centerX.equalToSuperview()
        }
    }
    
    @objc func mapy_buttonClick(sender: UIButton) {
        if sender == mapy_leftButton {
            if (mapy_leftBlock != nil) {
                mapy_leftBlock?()
                return
            }
            mapy_viewGetVController?.navigationController?.popViewController(animated: true)
            return
        }
    }
    
    var mapy_leftBlock:(()->())?
    
    lazy var mapy_leftButton: UIButton = {
        let mapy_leftButton = UIButton()
        mapy_leftButton.setImage(UIImage(named: "mapy_nav_back"), for: .normal)
        mapy_leftButton.addTarget(self, action: #selector(mapy_buttonClick(sender:)), for: .touchUpInside)
        return mapy_leftButton
    }()
    
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 18)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        return mapy_titleLabel
    }()
    
}

